<script setup>
const goToIndex = () => {
  uni.navigateTo({
    url:'index'
  });
};

import { ref } from 'vue';
const reason = ref(''); // 绑定输入框数据
const startTime = ref('');
const endTime = ref('');
const name = ref('');
const phone = ref('');

const accommodation = ref('');
  // 校内住宿信息
const dormInfo = ref('');
  // 校外住宿地址
const outsideAddress = ref('');
  // 处理住宿选项变更

const handleAccommodationChange = (e) => {
  accommodation.value = e.detail.value;
};
  // 提交登记逻辑
const submitRegister = () => {
  console.log('提交数据：', {
    accommodation: accommodation.value,
    dormInfo: dormInfo.value,
    outsideAddress: outsideAddress.value
    // 其他表单字段也可在此处收集
  });
};
</script>

<template>
  <view class="container">

    <form>

      <view class="form-item">

        <view class="label">
          <text class="text-normal">留校原因</text>
          <text class="text-required">*</text>
        </view>

        <textarea
            placeholder="请说明留校原因..."
            class="input"
            v-model="reason"
        ></textarea>

      </view>

      <view class="form-item">

        <view class="label">
          <text class="text-normal">计划留校开始时间</text>
          <text class="text-required">*</text>
        </view>

        <textarea
            placeholder="请输入计划留校开始时间"
            class="input time-input"
            v-model="startTime"
        ></textarea>

      </view>

      <view class="form-item">

        <view class="label">
          <text class="text-normal">计划留校结束时间</text>
          <text class="text-required">*</text>
        </view>

        <textarea
            placeholder="请输入计划留校结束时间"
            class="input time-input"
            v-model="endTime"
        ></textarea>

      </view>

      <view class="form-item">

        <view class="label">
          <text class="text-normal">家庭联系人姓名</text>
          <text class="text-required">*</text>
        </view>

        <textarea
            placeholder="请输入家庭联系人姓名"
            class="input name-input"
            v-model="name"
        ></textarea>

      </view>

      <view class="form-item">

        <view class="label">
          <text class="text-normal">家庭联系人电话</text>
          <text class="text-required">*</text>
        </view>

        <textarea
            placeholder="请输入家庭联系人电话"
            class="input phone-input"
            v-model="phone"
        ></textarea>

      </view>

    </form>

  </view>

  <view class="form-item">

    <text class="label">是否需要校内住宿 *</text>

    <radio-group
        @change="handleAccommodationChange"
        class="radio-group-inline"
    >

      <radio
          value="need"
          :checked="accommodation === 'need'"
          class="radio-item"
      >需要</radio>

      <radio
          value="notNeed"
          :checked="accommodation === 'notNeed'"
          class="radio-item"
      >不需要</radio>

    </radio-group>
  </view>

  <view class="form-item" v-if="accommodation === 'need'">
    <text class="label">宿舍楼及门牌号 *</text>
    <input v-model="dormInfo" placeholder="请输入宿舍楼及门牌号" />
  </view>

  <view class="form-item" v-else-if="accommodation === 'notNeed'">
    <text class="label">校外住宿地址 *</text>
    <input v-model="outsideAddress" placeholder="请输入校外住宿地址" />
  </view>

  <view>
    <button  @click="goToIndex">确认登记</button>
  </view>

</template>

<style scoped>
.container {
  padding: 20rpx;
}
.text-normal{
  color: #262626;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}
.text-required{
  color: #cb000e;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  margin-left: 4px;
}
.label {
  margin-top: 15rpx;
  margin-left: 5rpx;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}
.input {
  width: 335px;
  height: 100px;
  background: #FFFFFF;
  border-radius: 4px;
  border: 1rpx solid #ccc;
  padding: 15rpx;
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
  resize: none;
  overflow: auto;
  margin-left: 5rpx;
}
.input::placeholder{
  font-weight: 400;
  font-size: 12px;
  color: #ADADAD;
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}
.time-input{
  width: 335px;
  height: 25px;
  background: #FFFFFF;
  border-radius: 4px;
}
.name-input{
  width: 335px;
  height: 25px;
  background: #FFFFFF;
  border-radius: 4px;
}
.phone-input{
  width: 335px;
  height: 25px;
  background: #FFFFFF;
  border-radius: 4px;
}
.radio-group-inline {
  display: flex;
  align-items: center;
  margin-left: 5rpx;
}
.radio-item {
  display: flex;
  align-items: center;
  margin-right: 20px;
}
.radio-item text {
  margin-left: 6px;
  width: 36px;
  height: 22px;
  font-weight: 400;
  font-size: 12px;
  color: #000000e6;
  text-align: left;
  line-height: 22px;
}

.form-item {
  margin-bottom: 30rpx;
  display: flex;
  flex-direction: column;
}
.label {
  font-size: 28rpx;
  margin-bottom: 10rpx;
}
input {
  border: 1px solid #ccc;
  border-radius: 4rpx;
  padding: 15rpx;
  font-size: 28rpx;
}
radio-group {
  display: flex;
  flex-direction: row;
}
radio {
  margin-right: 30rpx;
}
button {
  background-color: #007AFF;
  color: #fff;
  border-radius: 8rpx;
  padding: 20rpx;
  font-size: 32rpx;
}
.radio-group-inline {
  display: flex;
  align-items: center;
  margin-left: 5rpx;
}
.radio-item {
  display: flex;
  align-items: center;
  margin-right: 20px;
}
.radio-item text {
  margin-left: 6px;
  width: 36px;
  height: 22px;
  font-weight: 400;
  font-size: 12px;
  color: #000000e6;
  text-align: left;
  line-height: 22px;
}
</style>